package com.cykj.shop.service.impl;

import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.shop.mapper.ShopMapper;
import com.cykj.shop.service.ShopService;
import com.cykj.shop.domain.vo.ShopVo;
import com.cykj.system.api.domain.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 叶佳伟
 * @date 2025/8/18
 * @description 功能描述: 店铺实现类
 */
@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopMapper shopMapper;

    @Override
    public AjaxResult showInfo(Integer businessId) {
        Shop shop = shopMapper.showInfo(businessId);
        if (shop != null) {
            System.out.println(shop);
            return AjaxResult.success(shop);
        }
        return AjaxResult.error("商家店铺信息显示失败");
    }


    //商家入驻
    @Override
    public AjaxResult addShop(ShopVo shopVo) {
        return null;
    }


    @Override
    public AjaxResult updateStatus(ShopVo shopVo) {
        Integer res = shopMapper.updateStatus(shopVo);
        if (res > 0) {
            return AjaxResult.success("店铺状态修改成功");
        }
        return AjaxResult.error("店铺状态修改失败");
    }

    @Override
    public AjaxResult updateInfo(ShopVo shopVo) {
        Integer res = shopMapper.updateInfo(shopVo);
        if (res > 0) {
            return AjaxResult.success("店铺信息修改成功");
        }
        return AjaxResult.error("店铺信息修改失败");
    }

    @Override
    public AjaxResult updateAvatar(Integer id, String shopAvatarUrl) {
        Integer res = shopMapper.updateAvatar(id, shopAvatarUrl);
        if (res > 0) {
            return AjaxResult.success("店铺头像修改成功");
        }
        return AjaxResult.error("店铺头像修改失败");
    }

    // 获取商家id
    @Override
    public AjaxResult getShopIdByBusinessId(Integer businessId) {
        Shop shop = shopMapper.showInfo(businessId);
        if (shop != null) {
            Map<String, Object> result = new HashMap<>();
            result.put("shopId", shop.getId());
            return AjaxResult.success(result);
        } else {
            return AjaxResult.error("未找到对应的店铺信息");
        }
    }

    @Override
    public AjaxResult getListShop(ShopVo shopVo) {

        List<Shop> shopList = shopMapper.getListShop(shopVo);

        return AjaxResult.success(shopList);
    }
}
